import * as server from "@minecraft/server";
import * as magic_cable from "./magic_cable";
import * as servo_drive from "./servo_drive";
import * as machine_gate from "./machine_gate";
import * as magic_weapon from "./magic_weapon";
import * as energy_module from "./energy_module";
import * as storage_manage from "./storage_manage";
import * as mineral_project from "./mineral_project";
import * as farming_project from "./farming_project";
import * as obsidian_smelting from "./obsidian_smelting";
import * as data_block from "../data/block";
import * as realm_property from "../system/realm_property";
import * as derived_tools from "../system/derived_tools";
import * as native_tools from "../system/native_tools";
import * as achieve_plan from "../system/achieve_plan";
import * as math_tools from "../system/math_tools";
const defaultState = 'STATE:rune_type';
const tickScore = new Map();
let routineLogisticsRequest = new Map();
let surpassDimensionRequest = new Map();
;
function blockTimer(block, bounds, after) {
    const position = math_tools.Vector.toString(block.location);
    const onTick = tickScore.get(position);
    if (!onTick || onTick[0] != block.typeId)
        tickScore.set(position, [block.typeId, 1]);
    else if (onTick && onTick[1] <= bounds)
        tickScore.set(position, [block.typeId, onTick[1] + 1]);
    else {
        tickScore.delete(math_tools.Vector.toString(block.location));
        try {
            return after(block);
        }
        catch (error) {
            return error;
        }
    }
}
;
function TickComponentTrigger(source) {
    const block = source.block;
    const state = source.block.permutation;
    const dimension = source.dimension;
    const condition = state.getState(defaultState) ?? 0;
    return { block, state, condition, dimension };
}
;
export function UnrealSpaceTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            if (analysis.state.getState('STATE:stage') == 0)
                native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 2);
            blockTimer(analysis.block, 20, block => block.setPermutation(server.BlockPermutation.resolve('minecraft:air')));
        }
    };
}
;
export function NihilitySpaceTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            analysis.dimension.playSound('use.stone', analysis.block.location);
            switch (analysis.state.getState('STATE:value')) {
                case 0:
                    native_tools.TrySetPermutation(analysis.block, 'STATE:value', 1);
                    break;
                case 1:
                    native_tools.TrySetPermutation(analysis.block, 'STATE:value', 2);
                    break;
                case 2:
                    native_tools.TrySetPermutation(analysis.block, 'STATE:value', 3);
                    break;
                case 3:
                    native_tools.TrySetPermutation(analysis.block, 'STATE:value', 4);
                    break;
                case 4:
                    native_tools.TrySetPermutation(analysis.block, 'STATE:value', 5);
                    break;
                case 5:
                    native_tools.TrySetPermutation(analysis.block, 'STATE:value', 6);
                    break;
                case 6:
                    native_tools.TrySetPermutation(analysis.block, 'STATE:value', 7);
                    break;
                case 7:
                    native_tools.TrySetPermutation(analysis.block, 'STATE:value', 8);
                    break;
                case 8:
                    native_tools.TrySetPermutation(analysis.block, 'STATE:value', 9);
                    break;
                default:
                    native_tools.TrySetPermutation(analysis.block, 'STATE:value', 10);
                    analysis.dimension.playSound('beacon.activate', analysis.block.location);
                    analysis.block.setPermutation(server.BlockPermutation.resolve('minecraft:air'));
                    break;
            }
        }
    };
}
;
export function BasicPipelineTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            if (analysis.condition != 0 && analysis.condition != 9)
                magic_cable.defaultEvent(analysis.block, 'Xx-Yy-Zz', analysis.state);
            else if (analysis.condition == 9) {
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:direction_positive.X', analysis.block.offset(math_tools.Vector.CONSTANT_EAST)?.hasTag('data_tag:magic_cable.port_negative.X') ?? false);
                native_tools.TrySetPermutation(analysis.block, 'STATE:direction_negative.X', analysis.block.offset(math_tools.Vector.CONSTANT_WEST)?.hasTag('data_tag:magic_cable.port_positive.X') ?? false);
                native_tools.TrySetPermutation(analysis.block, 'STATE:direction_positive.Y', analysis.block.offset(math_tools.Vector.CONSTANT_UP)?.hasTag('data_tag:magic_cable.port_negative.Y') ?? false);
                native_tools.TrySetPermutation(analysis.block, 'STATE:direction_negative.Y', analysis.block.offset(math_tools.Vector.CONSTANT_DOWN)?.hasTag('data_tag:magic_cable.port_positive.Y') ?? false);
                native_tools.TrySetPermutation(analysis.block, 'STATE:direction_negative.Z', analysis.block.offset(math_tools.Vector.CONSTANT_NORTH)?.hasTag('data_tag:magic_cable.port_positive.Z') ?? false);
                native_tools.TrySetPermutation(analysis.block, 'STATE:direction_positive.Z', analysis.block.offset(math_tools.Vector.CONSTANT_SOUTH)?.hasTag('data_tag:magic_cable.port_negative.Z') ?? false);
            }
            ;
        }
    };
}
;
export function PulselatchTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            function beforeEvent() {
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_note', analysis.condition);
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
                magic_cable.LatchUpdateEvent(analysis.block);
            }
            ;
            function afterEvent() {
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_note', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
            }
            ;
            if (analysis.condition != 0 && analysis.state.getState('STATE:rune_note') == 0)
                beforeEvent();
            else if (analysis.condition != 0 && analysis.state.getState('STATE:rune_note') != 0)
                afterEvent();
            native_tools.TrySetPermutation(analysis.block, 'STATE:direction_positive.X', (analysis.block.offset(math_tools.Vector.CONSTANT_EAST)?.hasTag('data_tag:magic_cable.port_negative.X') || analysis.block.offset(math_tools.Vector.CONSTANT_EAST)?.hasTag('data_tag:magic_cable.logic_negative.X')) ?? false);
            native_tools.TrySetPermutation(analysis.block, 'STATE:direction_negative.X', (analysis.block.offset(math_tools.Vector.CONSTANT_WEST)?.hasTag('data_tag:magic_cable.port_positive.X') || analysis.block.offset(math_tools.Vector.CONSTANT_WEST)?.hasTag('data_tag:magic_cable.logic_positive.X')) ?? false);
            native_tools.TrySetPermutation(analysis.block, 'STATE:direction_positive.Y', (analysis.block.offset(math_tools.Vector.CONSTANT_UP)?.hasTag('data_tag:magic_cable.port_negative.Y') || analysis.block.offset(math_tools.Vector.CONSTANT_UP)?.hasTag('data_tag:magic_cable.logic_negative.Y')) ?? false);
            native_tools.TrySetPermutation(analysis.block, 'STATE:direction_negative.Y', (analysis.block.offset(math_tools.Vector.CONSTANT_DOWN)?.hasTag('data_tag:magic_cable.port_positive.Y') || analysis.block.offset(math_tools.Vector.CONSTANT_DOWN)?.hasTag('data_tag:magic_cable.logic_positive.Y')) ?? false);
            native_tools.TrySetPermutation(analysis.block, 'STATE:direction_positive.Z', (analysis.block.offset(math_tools.Vector.CONSTANT_SOUTH)?.hasTag('data_tag:magic_cable.port_negative.Z') || analysis.block.offset(math_tools.Vector.CONSTANT_SOUTH)?.hasTag('data_tag:magic_cable.logic_negative.Z')) ?? false);
            native_tools.TrySetPermutation(analysis.block, 'STATE:direction_negative.Z', (analysis.block.offset(math_tools.Vector.CONSTANT_NORTH)?.hasTag('data_tag:magic_cable.port_positive.Z') || analysis.block.offset(math_tools.Vector.CONSTANT_NORTH)?.hasTag('data_tag:magic_cable.logic_positive.Z')) ?? false);
        }
    };
}
;
export function SuperOmphalosTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            if (analysis.condition != 0 && analysis.condition != 9)
                magic_cable.SuperOmphalos(analysis.block, analysis.state);
            else if (analysis.condition == 9)
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
        }
    };
}
;
export function SuperPulseTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            if (analysis.condition != 0 && analysis.condition != 9) {
                const start = analysis.block.location;
                const done = magic_cable.SuperPulse(analysis.block, analysis.state.getState('minecraft:block_face'));
                achieve_plan.PathExecute.Create('超导髓鞘-射线动画', 1, {
                    location_group: [start, done],
                    particles: ['constant:track_color_rainbow'],
                    offset: math_tools.Vector.CONSTANT_HALF,
                    dimension: analysis.dimension,
                    cooldown: 1,
                    speed: 1,
                });
            }
            else if (analysis.condition == 9)
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
        }
    };
}
;
export function EnableControlTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            if (analysis.condition != 0 && analysis.condition != 9) {
                const above = analysis.block.above();
                const below = analysis.block.below();
                const tag = 'data_tag:magic_cable.open';
                if (above?.hasTag(tag) || below?.hasTag(tag)) {
                    magic_cable.defaultEvent(analysis.block, 'Xx-0-Zz', analysis.state);
                    native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 1);
                }
                else if (!above?.hasTag(tag) && !below?.hasTag(tag)) {
                    native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 0);
                    native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
                }
            }
            else if (analysis.condition == 9)
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
        }
    };
}
;
export function RedstoneDetectionTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            magic_cable.RedstoneDetection(analysis.block, 'Xx-0-Zz');
        }
    };
}
;
export function CountingModuleTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            function beforeEvent() {
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:count', 0);
                magic_cable.logicComponents(analysis.block, 'Xx-Yy-Zz');
            }
            ;
            function afterEvent() {
                const count = analysis.state.getState('STATE:count');
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:count', count + 1);
            }
            ;
            if (analysis.state.getState('STATE:input') == analysis.state.getState('STATE:count'))
                beforeEvent();
            else if ((analysis.state.getState('STATE:input') != analysis.state.getState('STATE:count')) && analysis.state.getState('STATE:count') != 10)
                afterEvent();
        }
    };
}
;
export function ControlPanelTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            function beforeEvent() {
                switch (analysis.state.getState('minecraft:block_face')) {
                    case 'down':
                        magic_cable.interactiveTerminal(analysis.block, 'Xx-Y-Zz', analysis.state);
                        break;
                    case 'up':
                        magic_cable.interactiveTerminal(analysis.block, 'Xx-y-Zz', analysis.state);
                        break;
                    case 'north':
                        magic_cable.interactiveTerminal(analysis.block, 'Xx-Yy-Z', analysis.state);
                        break;
                    case 'south':
                        magic_cable.interactiveTerminal(analysis.block, 'Xx-Yy-z', analysis.state);
                        break;
                    case 'west':
                        magic_cable.interactiveTerminal(analysis.block, 'X-Yy-Zz', analysis.state);
                        break;
                    case 'east':
                        magic_cable.interactiveTerminal(analysis.block, 'x-Yy-Zz', analysis.state);
                        break;
                    default: break;
                }
                ;
                native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 2);
            }
            ;
            function afterEvent() {
                native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 0);
            }
            ;
            if (analysis.state.getState('STATE:stage') == 1)
                beforeEvent();
            else if (analysis.state.getState('STATE:stage') == 2)
                afterEvent();
        }
    };
}
;
export function LogicInverterTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            const face = analysis.state.getState('minecraft:block_face');
            const tag = 'data_tag:magic_cable.open';
            switch (face) {
                case 'up':
                    if (!analysis.block.offset(math_tools.Vector.CONSTANT_UP)?.hasTag(tag))
                        magic_cable.logicComponents(analysis.block, '0-y-0');
                    break;
                case 'down':
                    if (!analysis.block.offset(math_tools.Vector.CONSTANT_DOWN)?.hasTag(tag))
                        magic_cable.logicComponents(analysis.block, '0-Y-0');
                    break;
                case 'north':
                    if (!analysis.block.offset(math_tools.Vector.CONSTANT_NORTH)?.hasTag(tag))
                        magic_cable.logicComponents(analysis.block, '0-0-Z');
                    break;
                case 'south':
                    if (!analysis.block.offset(math_tools.Vector.CONSTANT_SOUTH)?.hasTag(tag))
                        magic_cable.logicComponents(analysis.block, '0-0-z');
                    break;
                case 'east':
                    if (!analysis.block.offset(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag))
                        magic_cable.logicComponents(analysis.block, 'x-0-0');
                    break;
                case 'west':
                    if (!analysis.block.offset(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag))
                        magic_cable.logicComponents(analysis.block, 'X-0-0');
                    break;
                default: break;
            }
        }
    };
}
;
export function ExclusiveOrTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            const target = (input) => analysis.block.offset(input);
            const face = analysis.state.getState('minecraft:block_face');
            const tag = 'data_tag:magic_cable.open';
            switch (face) {
                case 'up':
                    if (target(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag) || target(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag))
                        if (target(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag) != target(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag))
                            magic_cable.logicComponents(analysis.block, '0-y-0');
                    break;
                case 'down':
                    if (target(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag) || target(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag))
                        if (target(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag) != target(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag))
                            magic_cable.logicComponents(analysis.block, '0-Y-0');
                    break;
                case 'north':
                    if (target(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag) || target(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag))
                        if (target(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag) != target(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag))
                            magic_cable.logicComponents(analysis.block, '0-0-Z');
                    break;
                case 'south':
                    if (target(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag) || target(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag))
                        if (target(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag) != target(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag))
                            magic_cable.logicComponents(analysis.block, '0-0-z');
                    break;
                case 'east':
                    if (target(math_tools.Vector.CONSTANT_SOUTH)?.hasTag(tag) || target(math_tools.Vector.CONSTANT_NORTH)?.hasTag(tag))
                        if (target(math_tools.Vector.CONSTANT_SOUTH)?.hasTag(tag) != target(math_tools.Vector.CONSTANT_NORTH)?.hasTag(tag))
                            magic_cable.logicComponents(analysis.block, 'x-0-0');
                    break;
                case 'west':
                    if (target(math_tools.Vector.CONSTANT_SOUTH)?.hasTag(tag) || target(math_tools.Vector.CONSTANT_NORTH)?.hasTag(tag))
                        if (target(math_tools.Vector.CONSTANT_SOUTH)?.hasTag(tag) != target(math_tools.Vector.CONSTANT_NORTH)?.hasTag(tag))
                            magic_cable.logicComponents(analysis.block, 'X-0-0');
                    break;
                default: break;
            }
            ;
            native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 0);
        }
    };
}
;
export function ExclusiveAndTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            const target = (input) => analysis.block.offset(input);
            const face = analysis.state.getState('minecraft:block_face');
            const tag = 'data_tag:magic_cable.open';
            switch (face) {
                case 'up':
                    if (target(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag) && target(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag))
                        magic_cable.logicComponents(analysis.block, '0-y-0');
                    break;
                case 'down':
                    if (target(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag) && target(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag))
                        magic_cable.logicComponents(analysis.block, '0-Y-0');
                    break;
                case 'north':
                    if (target(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag) && target(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag))
                        magic_cable.logicComponents(analysis.block, '0-0-Z');
                    break;
                case 'south':
                    if (target(math_tools.Vector.CONSTANT_EAST)?.hasTag(tag) && target(math_tools.Vector.CONSTANT_WEST)?.hasTag(tag))
                        magic_cable.logicComponents(analysis.block, '0-0-z');
                    break;
                case 'east':
                    if (target(math_tools.Vector.CONSTANT_SOUTH)?.hasTag(tag) && target(math_tools.Vector.CONSTANT_NORTH)?.hasTag(tag))
                        magic_cable.logicComponents(analysis.block, 'x-0-0');
                    break;
                case 'west':
                    if (target(math_tools.Vector.CONSTANT_SOUTH)?.hasTag(tag) && target(math_tools.Vector.CONSTANT_NORTH)?.hasTag(tag))
                        magic_cable.logicComponents(analysis.block, 'X-0-0');
                    break;
                default: break;
            }
            ;
            native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 0);
        }
    };
}
;
export function SignalCompilationTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            function beforeEvent() {
                magic_cable.SignalCompilation(analysis.block, 'Xx-0-Zz', analysis.state);
            }
            ;
            function afterEvent() {
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:index', 0);
            }
            ;
            if (analysis.state.getState('STATE:stage') == 0 && analysis.state.getState('STATE:rune_type') != 0) {
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 1);
            }
            else if (analysis.state.getState('STATE:stage') == 1)
                beforeEvent();
            else if (analysis.state.getState('STATE:stage') == 2)
                afterEvent();
        }
    };
}
;
export function SignalFilteringTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            function beforeEvent() {
                magic_cable.signalProcessing(analysis.block, 'Xx-Yy-Zz', analysis.state);
            }
            ;
            function afterEvent() {
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
            }
            ;
            if (analysis.condition != 0 && analysis.condition != 9 && analysis.condition == analysis.state.getState('STATE:rune_note'))
                beforeEvent();
            if (analysis.condition != 0 && analysis.condition != 9 && analysis.condition != analysis.state.getState('STATE:rune_note'))
                afterEvent();
            else if (analysis.condition == 9)
                afterEvent();
        }
    };
}
;
export function SignalConversionTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            if (analysis.condition != 0 && analysis.condition != 9)
                magic_cable.signalProcessing(analysis.block, 'Xx-Yy-Zz', analysis.state);
            else if (analysis.condition == 9)
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
        }
    };
}
;
export function CablePortTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            if (analysis.condition != 0 && analysis.condition != 9) {
                const face = analysis.state.getState('minecraft:block_face');
                switch (face) {
                    case 'up':
                        magic_cable.defaultEvent(analysis.block, '0-Yy-0', analysis.state);
                        break;
                    case 'down':
                        magic_cable.defaultEvent(analysis.block, '0-Yy-0', analysis.state);
                        break;
                    case 'north':
                        magic_cable.defaultEvent(analysis.block, '0-0-Zz', analysis.state);
                        break;
                    case 'south':
                        magic_cable.defaultEvent(analysis.block, '0-0-Zz', analysis.state);
                        break;
                    case 'east':
                        magic_cable.defaultEvent(analysis.block, 'Xx-0-0', analysis.state);
                        break;
                    case 'west':
                        magic_cable.defaultEvent(analysis.block, 'Xx-0-0', analysis.state);
                        break;
                    default: break;
                }
            }
            else if (analysis.condition == 9)
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
        }
    };
}
;
export function PackageDeliveryTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            const face = analysis.state.getState('minecraft:block_face');
            storage_manage.Transmission(analysis.block, face);
            analysis.dimension?.playSound('beacon.deactivate', analysis.block.location);
            native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
        }
    };
}
;
export function PlacementTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            storage_manage.Placement(analysis.block);
            analysis.dimension?.playSound('beacon.deactivate', analysis.block.location);
            native_tools.TrySetPermutation(analysis.block, 'STATE:energy', math_tools.Random({ min: 0, max: 6 }, true));
            native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
        }
    };
}
;
export function CollectionTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            storage_manage.Collection(analysis.block, analysis.state);
            analysis.dimension?.playSound('beacon.deactivate', analysis.block.location);
            native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
        }
    };
}
;
export function SusceptorTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            function beforeEvent() {
                const hasTag = (offset, tag) => analysis.block.offset(offset)?.getTags().includes(tag) ?? false;
                switch (analysis.condition) {
                    case 1:
                        if (hasTag({ x: 1, y: -1, z: 0 }, 'data_tag:magic_cable.series'))
                            if (!hasTag(math_tools.Vector.CONSTANT_EAST, 'data_tag:magic_cable.series'))
                                servo_drive.Susceptor(analysis.block, 'X+');
                        break;
                    case 2:
                        if (hasTag({ x: -1, y: -1, z: 0 }, 'data_tag:magic_cable.series'))
                            if (!hasTag(math_tools.Vector.CONSTANT_WEST, 'data_tag:magic_cable.series'))
                                servo_drive.Susceptor(analysis.block, 'X-');
                        break;
                    case 3:
                        if (hasTag({ x: 0, y: -1, z: 1 }, 'data_tag:magic_cable.series'))
                            if (!hasTag(math_tools.Vector.CONSTANT_SOUTH, 'data_tag:magic_cable.series'))
                                servo_drive.Susceptor(analysis.block, 'Z+');
                        break;
                    case 4:
                        if (hasTag({ x: -0, y: -1, z: -1 }, 'data_tag:magic_cable.series'))
                            if (!hasTag(math_tools.Vector.CONSTANT_NORTH, 'data_tag:magic_cable.series'))
                                servo_drive.Susceptor(analysis.block, 'Z-');
                        break;
                    default: break;
                }
                ;
                for (let index = 0; index <= 5; index++) {
                    const tag = 'data_tag:servo_machine.value.' + index;
                    if (hasTag(math_tools.Vector.CONSTANT_EAST, tag))
                        native_tools.TrySetPermutation(analysis.block, 'STATE:value', index);
                    if (hasTag(math_tools.Vector.CONSTANT_WEST, tag))
                        native_tools.TrySetPermutation(analysis.block, 'STATE:value', index);
                    if (hasTag(math_tools.Vector.CONSTANT_SOUTH, tag))
                        native_tools.TrySetPermutation(analysis.block, 'STATE:value', index);
                    if (hasTag(math_tools.Vector.CONSTANT_NORTH, tag))
                        native_tools.TrySetPermutation(analysis.block, 'STATE:value', index);
                }
                ;
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
            }
            ;
            function afterEvent() {
                const direction = analysis.state.getState('STATE:direction');
                native_tools.TrySetPermutation(analysis.block, 'STATE:direction', 0);
                switch (direction) {
                    case 1:
                        for (let index = 0; index <= 5; index++) {
                            if (index != analysis.state.getState('STATE:value'))
                                continue;
                            const anchor_0 = math_tools.Vector.toString(analysis.block, { delimiter: ' ' });
                            const anchor_1 = math_tools.Vector.toString(analysis.block.offset(math_tools.Vector.CONSTANT_EAST), { delimiter: ' ' });
                            const anchor_2 = math_tools.Vector.toString(analysis.block.offset({ x: 1, y: index, z: 0 }), { delimiter: ' ' });
                            const anchor_3 = math_tools.Vector.toString(analysis.block.offset({ x: 0, y: index, z: 0 }), { delimiter: ' ' });
                            analysis.dimension.runCommand(`fill ${anchor_1} ${anchor_2} air [] destroy`);
                            analysis.dimension.runCommand(`clone ${anchor_0} ${anchor_3} ${anchor_1} replace move`);
                            analysis.dimension.runCommand(`fill ${anchor_0} ${anchor_0} air`);
                        }
                        ;
                        break;
                    case 2:
                        for (let index = 0; index <= 5; index++) {
                            if (index != analysis.state.getState('STATE:value'))
                                continue;
                            const anchor_0 = math_tools.Vector.toString(analysis.block, { delimiter: ' ' });
                            const anchor_1 = math_tools.Vector.toString(analysis.block.offset(math_tools.Vector.CONSTANT_WEST), { delimiter: ' ' });
                            const anchor_2 = math_tools.Vector.toString(analysis.block.offset({ x: -1, y: index, z: 0 }), { delimiter: ' ' });
                            const anchor_3 = math_tools.Vector.toString(analysis.block.offset({ x: 0, y: index, z: 0 }), { delimiter: ' ' });
                            analysis.dimension.runCommand(`fill ${anchor_1} ${anchor_2} air [] destroy`);
                            analysis.dimension.runCommand(`clone ${anchor_0} ${anchor_3} ${anchor_1} replace move`);
                            analysis.dimension.runCommand(`fill ${anchor_0} ${anchor_0} air`);
                        }
                        ;
                        break;
                    case 3:
                        for (let index = 0; index <= 5; index++) {
                            if (index != analysis.state.getState('STATE:value'))
                                continue;
                            const anchor_0 = math_tools.Vector.toString(analysis.block, { delimiter: ' ' });
                            const anchor_1 = math_tools.Vector.toString(analysis.block.offset(math_tools.Vector.CONSTANT_SOUTH), { delimiter: ' ' });
                            const anchor_2 = math_tools.Vector.toString(analysis.block.offset({ x: 0, y: index, z: 1 }), { delimiter: ' ' });
                            const anchor_3 = math_tools.Vector.toString(analysis.block.offset({ x: 0, y: index, z: 0 }), { delimiter: ' ' });
                            analysis.dimension.runCommand(`fill ${anchor_1} ${anchor_2} air [] destroy`);
                            analysis.dimension.runCommand(`clone ${anchor_0} ${anchor_3} ${anchor_1} replace move`);
                            analysis.dimension.runCommand(`fill ${anchor_0} ${anchor_0} air`);
                        }
                        ;
                        break;
                    case 4:
                        for (let index = 0; index <= 5; index++) {
                            if (index != analysis.state.getState('STATE:value'))
                                continue;
                            const anchor_0 = math_tools.Vector.toString(analysis.block, { delimiter: ' ' });
                            const anchor_1 = math_tools.Vector.toString(analysis.block.offset(math_tools.Vector.CONSTANT_NORTH), { delimiter: ' ' });
                            const anchor_2 = math_tools.Vector.toString(analysis.block.offset({ x: 0, y: index, z: -1 }), { delimiter: ' ' });
                            const anchor_3 = math_tools.Vector.toString(analysis.block.offset({ x: 0, y: index, z: 0 }), { delimiter: ' ' });
                            analysis.dimension.runCommand(`fill ${anchor_1} ${anchor_2} air [] destroy`);
                            analysis.dimension.runCommand(`clone ${anchor_0} ${anchor_3} ${anchor_1} replace move`);
                            analysis.dimension.runCommand(`fill ${anchor_0} ${anchor_0} air`);
                        }
                        ;
                        break;
                    default: break;
                }
                ;
            }
            ;
            if (analysis.condition != 0)
                beforeEvent();
            else if (analysis.state.getState('STATE:direction') != 0)
                afterEvent();
        }
    };
}
;
export function TractionTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            function beforeEvent() {
                const hasTag = (offset, tag) => analysis.block.offset(offset)?.getTags().includes(tag) ?? false;
                switch (analysis.condition) {
                    case 1:
                        if (hasTag({ x: 1, y: 1, z: 0 }, 'data_tag:magic_cable.series'))
                            if (!hasTag(math_tools.Vector.CONSTANT_EAST, 'data_tag:magic_cable.series'))
                                servo_drive.Susceptor(analysis.block, 'X+');
                        break;
                    case 2:
                        if (hasTag({ x: -1, y: 1, z: 0 }, 'data_tag:magic_cable.series'))
                            if (!hasTag(math_tools.Vector.CONSTANT_WEST, 'data_tag:magic_cable.series'))
                                servo_drive.Susceptor(analysis.block, 'X-');
                        break;
                    case 3:
                        if (hasTag({ x: 0, y: 1, z: 1 }, 'data_tag:magic_cable.series'))
                            if (!hasTag(math_tools.Vector.CONSTANT_SOUTH, 'data_tag:magic_cable.series'))
                                servo_drive.Susceptor(analysis.block, 'Z+');
                        break;
                    case 4:
                        if (hasTag({ x: -0, y: 1, z: -1 }, 'data_tag:magic_cable.series'))
                            if (!hasTag(math_tools.Vector.CONSTANT_NORTH, 'data_tag:magic_cable.series'))
                                servo_drive.Susceptor(analysis.block, 'Z-');
                        break;
                    default: break;
                }
                ;
                for (let index = 0; index <= 5; index++) {
                    const tag = 'data_tag:servo_machine.value.' + index;
                    if (hasTag(math_tools.Vector.CONSTANT_EAST, tag))
                        native_tools.TrySetPermutation(analysis.block, 'STATE:value', index);
                    if (hasTag(math_tools.Vector.CONSTANT_WEST, tag))
                        native_tools.TrySetPermutation(analysis.block, 'STATE:value', index);
                    if (hasTag(math_tools.Vector.CONSTANT_SOUTH, tag))
                        native_tools.TrySetPermutation(analysis.block, 'STATE:value', index);
                    if (hasTag(math_tools.Vector.CONSTANT_NORTH, tag))
                        native_tools.TrySetPermutation(analysis.block, 'STATE:value', index);
                }
                ;
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
            }
            ;
            function afterEvent() {
                const direction = analysis.state.getState('STATE:direction');
                native_tools.TrySetPermutation(analysis.block, 'STATE:direction', 0);
                switch (direction) {
                    case 1:
                        for (let index = 0; index <= 5; index++) {
                            if (index != analysis.state.getState('STATE:value'))
                                continue;
                            const anchor_0 = math_tools.Vector.toString(analysis.block, { delimiter: ' ' });
                            const anchor_1 = math_tools.Vector.toString(analysis.block.offset(math_tools.Vector.CONSTANT_EAST), { delimiter: ' ' });
                            const anchor_2 = math_tools.Vector.toString(analysis.block.offset({ x: 1, y: -index, z: 0 }), { delimiter: ' ' });
                            const anchor_3 = math_tools.Vector.toString(analysis.block.offset({ x: 0, y: -index, z: 0 }), { delimiter: ' ' });
                            analysis.dimension.runCommand(`fill ${anchor_1} ${anchor_2} air [] destroy`);
                            analysis.dimension.runCommand(`clone ${anchor_0} ${anchor_3} ${anchor_2} replace move`);
                            analysis.dimension.runCommand(`fill ${anchor_0} ${anchor_0} air`);
                        }
                        ;
                        break;
                    case 2:
                        for (let index = 0; index <= 5; index++) {
                            if (index != analysis.state.getState('STATE:value'))
                                continue;
                            const anchor_0 = math_tools.Vector.toString(analysis.block, { delimiter: ' ' });
                            const anchor_1 = math_tools.Vector.toString(analysis.block.offset(math_tools.Vector.CONSTANT_WEST), { delimiter: ' ' });
                            const anchor_2 = math_tools.Vector.toString(analysis.block.offset({ x: -1, y: -index, z: 0 }), { delimiter: ' ' });
                            const anchor_3 = math_tools.Vector.toString(analysis.block.offset({ x: 0, y: -index, z: 0 }), { delimiter: ' ' });
                            analysis.dimension.runCommand(`fill ${anchor_1} ${anchor_2} air [] destroy`);
                            analysis.dimension.runCommand(`clone ${anchor_0} ${anchor_3} ${anchor_2} replace move`);
                            analysis.dimension.runCommand(`fill ${anchor_0} ${anchor_0} air`);
                        }
                        ;
                        break;
                    case 3:
                        for (let index = 0; index <= 5; index++) {
                            if (index != analysis.state.getState('STATE:value'))
                                continue;
                            const anchor_0 = math_tools.Vector.toString(analysis.block, { delimiter: ' ' });
                            const anchor_1 = math_tools.Vector.toString(analysis.block.offset(math_tools.Vector.CONSTANT_SOUTH), { delimiter: ' ' });
                            const anchor_2 = math_tools.Vector.toString(analysis.block.offset({ x: 0, y: -index, z: 1 }), { delimiter: ' ' });
                            const anchor_3 = math_tools.Vector.toString(analysis.block.offset({ x: 0, y: -index, z: 0 }), { delimiter: ' ' });
                            analysis.dimension.runCommand(`fill ${anchor_1} ${anchor_2} air [] destroy`);
                            analysis.dimension.runCommand(`clone ${anchor_0} ${anchor_3} ${anchor_2} replace move`);
                            analysis.dimension.runCommand(`fill ${anchor_0} ${anchor_0} air`);
                        }
                        ;
                        break;
                    case 4:
                        for (let index = 0; index <= 5; index++) {
                            if (index != analysis.state.getState('STATE:value'))
                                continue;
                            const anchor_0 = math_tools.Vector.toString(analysis.block, { delimiter: ' ' });
                            const anchor_1 = math_tools.Vector.toString(analysis.block.offset(math_tools.Vector.CONSTANT_NORTH), { delimiter: ' ' });
                            const anchor_2 = math_tools.Vector.toString(analysis.block.offset({ x: 0, y: -index, z: -1 }), { delimiter: ' ' });
                            const anchor_3 = math_tools.Vector.toString(analysis.block.offset({ x: 0, y: -index, z: 0 }), { delimiter: ' ' });
                            analysis.dimension.runCommand(`fill ${anchor_1} ${anchor_2} air [] destroy`);
                            analysis.dimension.runCommand(`clone ${anchor_0} ${anchor_3} ${anchor_2} replace move`);
                            analysis.dimension.runCommand(`fill ${anchor_0} ${anchor_0} air`);
                        }
                        ;
                        break;
                    default: break;
                }
                ;
            }
            ;
            if (analysis.condition != 0)
                beforeEvent();
            else if (analysis.state.getState('STATE:direction') != 0)
                afterEvent();
        }
    };
}
;
export function OmphalosTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            analysis.dimension?.playSound('beacon.deactivate', analysis.block.location);
            native_tools.TrySetPermutation(analysis.block, 'STATE:stage', math_tools.Random({ min: 0, max: 6 }, true));
            native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
            switch (analysis.condition) {
                case 1:
                    servo_drive.Omphalos(analysis.block, 'X+');
                    break;
                case 2:
                    servo_drive.Omphalos(analysis.block, 'X-');
                    break;
                case 3:
                    servo_drive.Omphalos(analysis.block, 'Z+');
                    break;
                case 4:
                    servo_drive.Omphalos(analysis.block, 'Z-');
                    break;
                case 5:
                    servo_drive.Omphalos(analysis.block, 'Y+');
                    break;
                case 6:
                    servo_drive.Omphalos(analysis.block, 'Y-');
                    break;
                default: break;
            }
        }
    };
}
;
export function PlaneGateTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            analysis.dimension?.playSound('close.iron_door', analysis.block.location);
            native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 9);
            machine_gate.PlaneGate(analysis.block);
        }
    };
}
;
export function VerticalGateTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            analysis.dimension?.playSound('close.iron_door', analysis.block.location);
            native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 9);
            machine_gate.VerticalGate(analysis.block);
        }
    };
}
;
export function PortalAboveTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            function beforeEvent() {
                native_tools.TrySpawnParticle(analysis.dimension, 'constant:prompt_transport_above', analysis.block.bottomCenter());
                analysis.dimension?.playSound('conduit.activate', analysis.block.location);
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 9);
                machine_gate.AboveTeleport(analysis.block);
            }
            ;
            function afterEvent() {
                analysis.dimension?.playSound('place.amethyst_block', analysis.block.location);
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
            }
            ;
            if (analysis.condition != 0 && analysis.condition != 9)
                beforeEvent();
            else if (analysis.condition == 9)
                afterEvent();
        }
    };
}
;
export function PortalBelowTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            function beforeEvent() {
                native_tools.TrySpawnParticle(analysis.dimension, 'constant:prompt_transport_below', analysis.block.center());
                analysis.dimension?.playSound('conduit.activate', analysis.block.location);
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 9);
                machine_gate.BelowTeleport(analysis.block);
            }
            ;
            function afterEvent() {
                analysis.dimension?.playSound('place.amethyst_block', analysis.block.location);
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
            }
            ;
            if (analysis.condition != 0 && analysis.condition != 9)
                beforeEvent();
            else if (analysis.condition == 9)
                afterEvent();
        }
    };
}
;
export function DioriteTableTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            const getProperty = server.world.getDynamicProperty('block:diorite_table');
            if (!getProperty) {
                const particles = [];
                for (let index = 0; index < 3; index++) {
                    particles.push(derived_tools.AnalysisWeight(data_block.diorite_table_random_items).output);
                }
                const binding = JSON.stringify([{ x: analysis.block.x, y: analysis.block.y, z: analysis.block.z, particles }]);
                server.world.setDynamicProperty('block:diorite_table', binding);
                return;
            }
            ;
            const unpack = JSON.parse(getProperty);
            const intel = unpack.filter(value => math_tools.Vector.equals(value, analysis.block));
            if (intel.length == 0) {
                const particles = [];
                for (let index = 0; index < 3; index++) {
                    particles.push(derived_tools.AnalysisWeight(data_block.diorite_table_random_items).output);
                }
                unpack.push({ x: analysis.block.x, y: analysis.block.y, z: analysis.block.z, particles });
                server.world.setDynamicProperty('block:diorite_table', JSON.stringify(unpack));
            }
            else {
                const dimension = analysis.dimension;
                const CreateCase = (name, offset) => native_tools.TrySpawnParticle(dimension, name, math_tools.Vector.add(analysis.block, offset));
                intel[0].particles.forEach((value, index) => CreateCase(value, { x: 0.5, y: 1 + (index * 0.05), z: 0.5 }));
            }
            ;
        }
    };
}
;
export function JungleWoodChairTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            const players = analysis.dimension.getPlayers({ location: analysis.block.above()?.bottomCenter(), maxDistance: 0.5 });
            if (players.length == 0)
                return;
            players.forEach(player => player.playAnimation('animation.entity.sit_down.player'));
        }
    };
}
;
export function StoneMachineTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            function beforeEvent() {
                const value = analysis.state.getState('STATE:value');
                native_tools.TrySetPermutation(analysis.block, 'STATE:value', value - 1);
            }
            ;
            function middleEvent() {
                analysis.dimension?.playSound('random.fizz', analysis.block.location);
                native_tools.TrySetPermutation(analysis.block, 'STATE:value', 5);
            }
            ;
            function afterEvent() {
                analysis.dimension?.playSound('bucket.empty_lava', analysis.block.location);
                mineral_project.Solidify(analysis.block);
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:value', 0);
            }
            ;
            const value = analysis.state.getState('STATE:value');
            if (value != 0 && value != 1)
                beforeEvent();
            else if (value == 0)
                middleEvent();
            else if (value == 1)
                afterEvent();
        }
    };
}
;
export function MetalFormingPressTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            function beforeEvent() {
                const value = analysis.state.getState('STATE:value');
                analysis.dimension?.playSound('block.stonecutter.use', analysis.block.location);
                native_tools.TrySetPermutation(analysis.block, 'STATE:value', value + 1);
            }
            ;
            function afterEvent() {
                analysis.dimension?.playSound('random.anvil_land', analysis.block.location);
                mineral_project.Forming(analysis.block);
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:value', 0);
            }
            ;
            const value = analysis.state.getState('STATE:value');
            if (value != 7)
                beforeEvent();
            else if (value == 7)
                afterEvent();
        }
    };
}
;
export function DestroyTheCoreTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            mineral_project.Destroy(analysis.block, analysis.state.getState('minecraft:block_face'));
            native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
        }
    };
}
;
export function MineralMachineTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            function beforeEvent() {
                analysis.dimension?.playSound('block.stonecutter.use', analysis.block.location);
                native_tools.TrySetPermutation(analysis.block, 'STATE:value', analysis.state.getState('STATE:value') + 1);
            }
            ;
            function afterEvent() {
                analysis.dimension?.playSound('random.anvil_land', analysis.block.location);
                mineral_project.Mine(analysis.block);
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:value', 0);
            }
            ;
            if (analysis.state.getState('STATE:value') != 8)
                beforeEvent();
            else if (analysis.state.getState('STATE:value') == 8)
                afterEvent();
        }
    };
}
;
export function EnergySupplyTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            energy_module.Supply(analysis.block, analysis.state.getState('STATE:energy'));
            native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 0);
        }
    };
}
;
export function WindPowerTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            const rotate = analysis.state.getState('STATE:rotate');
            const type = analysis.state.getState('STATE:stage');
            native_tools.TrySetPermutation(analysis.block, 'STATE:rotate', rotate != 2 ? rotate + 1 : 0);
            native_tools.TrySetPermutation(analysis.block, 'STATE:stage', type != 9 ? type + 1 : 0);
            energy_module.Wind(analysis.block);
        }
    };
}
;
export function CrystalTankTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            const onTag = analysis.block.above()?.getTags()?.includes('data_tag:energy_module.node');
            const caching = analysis.state.getState('STATE:caching');
            if (!onTag && analysis.state.getState('STATE:output') == 1)
                analysis.dimension?.playSound('block.grindstone.use', analysis.block.location);
            if (onTag) {
                const index = math_tools.Random({ max: 4, min: 0 }, true);
                switch (index) {
                    case 0:
                        native_tools.TrySpawnParticle(analysis.dimension, 'constant:excite_rune_red', analysis.block.above()?.bottomCenter());
                        break;
                    case 1:
                        native_tools.TrySpawnParticle(analysis.dimension, 'constant:excite_rune_blue', analysis.block.above()?.bottomCenter());
                        break;
                    case 2:
                        native_tools.TrySpawnParticle(analysis.dimension, 'constant:excite_rune_green', analysis.block.above()?.bottomCenter());
                        break;
                    case 3:
                        native_tools.TrySpawnParticle(analysis.dimension, 'constant:excite_rune_orange', analysis.block.above()?.bottomCenter());
                        break;
                    case 4:
                        native_tools.TrySpawnParticle(analysis.dimension, 'constant:excite_rune_purple', analysis.block.above()?.bottomCenter());
                        break;
                    default: break;
                }
                ;
                native_tools.TrySetPermutation(analysis.block, 'STATE:caching', caching + Math.floor(Math.random() * 2));
                if (caching == 8)
                    analysis.block.setPermutation(server.BlockPermutation.resolve('block_energy:empty_tank'));
                energy_module.Tank(analysis.block);
            }
            ;
            native_tools.TrySetPermutation(analysis.block, 'STATE:output', onTag ? 1 : 0);
        }
    };
}
;
export function TransformTankTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            const constant = server.BlockPermutation.resolve('block_energy:release_tank');
            switch (math_tools.Random({ max: 4, min: 0 }, true)) {
                case 0:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:fireworks_fireball_rune_red', analysis.block.above()?.bottomCenter());
                    break;
                case 1:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:fireworks_fireball_rune_blue', analysis.block.above()?.bottomCenter());
                    break;
                case 2:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:fireworks_fireball_rune_green', analysis.block.above()?.bottomCenter());
                    break;
                case 3:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:fireworks_fireball_rune_orange', analysis.block.above()?.bottomCenter());
                    break;
                case 4:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:fireworks_fireball_rune_purple', analysis.block.above()?.bottomCenter());
                    break;
                default: break;
            }
            ;
            switch (math_tools.Random({ max: 4, min: 0 }, true)) {
                case 0:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:pulse_rune_red', analysis.block.above()?.bottomCenter());
                    break;
                case 1:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:pulse_rune_blue', analysis.block.above()?.bottomCenter());
                    break;
                case 2:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:pulse_rune_green', analysis.block.above()?.bottomCenter());
                    break;
                case 3:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:pulse_rune_orange', analysis.block.above()?.bottomCenter());
                    break;
                case 4:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:pulse_rune_purple', analysis.block.above()?.bottomCenter());
                    break;
                default: break;
            }
            ;
            switch (math_tools.Random({ max: 4, min: 0 }, true)) {
                case 0:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:erupt_rune_red', analysis.block.above()?.bottomCenter());
                    break;
                case 1:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:erupt_rune_blue', analysis.block.above()?.bottomCenter());
                    break;
                case 2:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:erupt_rune_green', analysis.block.above()?.bottomCenter());
                    break;
                case 3:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:erupt_rune_orange', analysis.block.above()?.bottomCenter());
                    break;
                case 4:
                    native_tools.TrySpawnParticle(analysis.dimension, 'constant:erupt_rune_purple', analysis.block.above()?.bottomCenter());
                    break;
                default: break;
            }
            ;
            analysis.dimension.playSound('cauldron.explode', analysis.block.location);
            analysis.block.setPermutation(constant);
        }
    };
}
;
export function AllocationPowerTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            const onTag = analysis.block.above()?.getTags()?.includes('data_tag:energy_module.node');
            if (!onTag)
                return;
            native_tools.TrySetPermutation(analysis.block, 'STATE:output', 0);
            energy_module.Tank(analysis.block);
        }
    };
}
;
export function MagmaPowerTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            const count = analysis.state.getState('STATE:count');
            const magma = analysis.state.getState('STATE:magma');
            analysis.dimension?.playSound('fire.fire', analysis.block.location);
            energy_module.Magma(analysis.block);
            blockTimer(analysis.block, 2, () => {
                if (count == 0) {
                    native_tools.TrySetPermutation(analysis.block, 'STATE:count', 15);
                    native_tools.TrySetPermutation(analysis.block, 'STATE:magma', magma - 1);
                }
                else {
                    native_tools.TrySetPermutation(analysis.block, 'STATE:count', count - 1);
                }
                ;
            });
        }
    };
}
;
export function WaterPowerTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            function beforeEvent() {
                const air = server.BlockPermutation.resolve('minecraft:air');
                const water = server.BlockPermutation.resolve('minecraft:water');
                const anchor_a = math_tools.Vector.add(analysis.block.location, math_tools.Vector.CONSTANT_ONE);
                const anchor_b = math_tools.Vector.add(analysis.block.location, math_tools.Vector.CONSTANT_LOSS_ONE);
                const isWater = analysis.block.below()?.isLiquid;
                const current = analysis.state.getState('STATE:stage');
                if (isWater)
                    native_tools.TrySetPermutation(analysis.block, 'STATE:stage', current + 1);
                native_tools.TryFillBlocks(analysis.dimension, anchor_a, anchor_b, air, { blockFilter: { includePermutations: [water] } });
            }
            ;
            function afterEvent() { energy_module.Water(analysis.block); }
            ;
            if (analysis.state.getState('STATE:stage') !== 9)
                beforeEvent();
            else
                afterEvent();
        }
    };
}
;
export function PlantingAndLoggingTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            function beforeEvent() {
                const stage = analysis.state.getState('STATE:stage');
                analysis.dimension.playSound('block.composter.fill_success', analysis.block.location);
                native_tools.TrySetPermutation(analysis.block, 'STATE:stage', stage + 1);
            }
            ;
            function afterEvent() {
                native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 0);
                farming_project.Forestry(analysis.block);
            }
            if (analysis.state.getState('STATE:stage') !== 5)
                beforeEvent();
            else
                afterEvent();
        }
    };
}
;
export function CropDetectionTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            const onTag = analysis.block.above()?.getTags()?.includes('data_tag:magic_cable.open');
            if (onTag)
                analysis.dimension.playSound('block.composter.ready', analysis.block.location);
            if (onTag)
                farming_project.Detection(analysis.block);
        }
    };
}
;
export function MagicCrystalLampTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            const light = analysis.state.getState('STATE:light');
            if (analysis.condition <= 3 && light != 15)
                native_tools.TrySetPermutation(analysis.block, 'STATE:light', light + 1);
            if (analysis.condition >= 4 && light != 0)
                native_tools.TrySetPermutation(analysis.block, 'STATE:light', light - 1);
            if (analysis.condition == 6)
                native_tools.TrySetPermutation(analysis.block, 'STATE:light', 15);
            if (analysis.condition == 7)
                native_tools.TrySetPermutation(analysis.block, 'STATE:light', 0);
            native_tools.TrySetPermutation(analysis.block, 'STATE:rune_type', 0);
        }
    };
}
;
export function WindAndRainTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            const particle = analysis.state.getState('STATE:particle');
            const stage = analysis.state.getState('STATE:stage');
            const onTag = analysis.block.below()?.getTags()?.includes('data_tag:magic_cable.open');
            if (!onTag)
                return;
            if (stage == 0)
                native_tools.TrySpawnParticle(analysis.dimension, 'constant:impact_rune_white', analysis.block.location);
            if (stage == 0)
                native_tools.TrySpawnParticle(analysis.dimension, particle, analysis.block.location);
            native_tools.TrySetPermutation(analysis.block, 'STATE:stage', stage != 3 ? stage + 1 : 0);
        }
    };
}
;
export function PulsePeakCannonTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            const onTag = analysis.block.below()?.getTags()?.includes('data_tag:magic_cable.open');
            if (onTag)
                magic_weapon.PulsePeakCannon(analysis.block);
        }
    };
}
;
export function FurnaceTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            function beforeEvent() {
                const material = analysis.state.getState('STATE:material');
                const stage = analysis.state.getState('STATE:stage');
                const magma = analysis.state.getState('STATE:magma');
                if (stage == 1 && material != 0) {
                    native_tools.TrySetPermutation(analysis.block, 'STATE:material', material - 1);
                    native_tools.TrySetPermutation(analysis.block, 'STATE:magma', magma + 1);
                    native_tools.TrySetPermutation(analysis.block, 'STATE:direction_0', 0);
                    native_tools.TrySetPermutation(analysis.block, 'STATE:direction_1', 0);
                    native_tools.TrySetPermutation(analysis.block, 'STATE:direction_2', 0);
                    native_tools.TrySetPermutation(analysis.block, 'STATE:direction_3', 0);
                    native_tools.TrySetPermutation(analysis.block, 'STATE:stage', 0);
                }
                else if (stage == 0)
                    obsidian_smelting.Attrition(analysis.block);
            }
            ;
            function afterEvent() {
                const direction_0 = analysis.block.offset({ x: 0, y: -1, z: -1 })?.getTags()?.includes('data_tag:obsidian_smelting.storage_tank');
                const direction_1 = analysis.block.offset({ x: -1, y: -1, z: 0 })?.getTags()?.includes('data_tag:obsidian_smelting.storage_tank');
                const direction_2 = analysis.block.offset({ x: 0, y: -1, z: 1 })?.getTags()?.includes('data_tag:obsidian_smelting.storage_tank');
                const direction_3 = analysis.block.offset({ x: 1, y: -1, z: 0 })?.getTags()?.includes('data_tag:obsidian_smelting.storage_tank');
                native_tools.TrySetPermutation(analysis.block, 'STATE:direction_0', direction_0 ? 1 : 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:direction_1', direction_1 ? 1 : 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:direction_2', direction_2 ? 1 : 0);
                native_tools.TrySetPermutation(analysis.block, 'STATE:direction_3', direction_3 ? 1 : 0);
                obsidian_smelting.Pouring(analysis.block);
            }
            const magma = analysis.state.getState('STATE:magma');
            if (magma != 8)
                beforeEvent();
            if (magma == 8)
                afterEvent();
        }
    };
}
;
export function EnergyExpendTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            const expend = analysis.state.getState('STATE:energy_expend');
            const energy = realm_property.ExpendEnergy(analysis.block, expend);
            if (energy)
                native_tools.TrySetPermutation(analysis.block, 'STATE:energy_stage', 2);
            else
                native_tools.TrySetPermutation(analysis.block, 'STATE:energy_stage', 0);
        }
    };
}
;
export function RoutineLogisticsReceiverTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            const direction = analysis.state.getState('minecraft:cardinal_direction');
            function Detecting(target) {
                const frame = analysis.block.above()?.getItemStack(1);
                const container = target?.getComponent('inventory')?.container;
                if (!target || !frame || !container || container.emptySlotsCount == 0)
                    return;
                const channel = frame.typeId;
                const filter = container.getItem(0)?.typeId ?? frame.typeId;
                routineLogisticsRequest.set(analysis.dimension.id + '•' + channel + '•' + filter, target.location);
            }
            ;
            switch (direction) {
                case 'south':
                    Detecting(analysis.block.south());
                    break;
                case 'north':
                    Detecting(analysis.block.north());
                    break;
                case 'east':
                    Detecting(analysis.block.east());
                    break;
                case 'west':
                    Detecting(analysis.block.west());
                    break;
                default: break;
            }
        }
    };
}
;
export function SurpassLogisticsReceiverTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            const direction = analysis.state.getState('minecraft:cardinal_direction');
            function Detecting(target) {
                const frame = analysis.block.above()?.getItemStack(1);
                const container = target?.getComponent('inventory')?.container;
                if (!target || !frame || !container || container.emptySlotsCount == 0)
                    return;
                const channel = frame.typeId;
                const filter = container.getItem(0)?.typeId ?? frame.typeId;
                surpassDimensionRequest.set(channel + '•' + filter, [target.dimension, target.location]);
            }
            ;
            switch (direction) {
                case 'south':
                    Detecting(analysis.block.south());
                    break;
                case 'north':
                    Detecting(analysis.block.north());
                    break;
                case 'east':
                    Detecting(analysis.block.east());
                    break;
                case 'west':
                    Detecting(analysis.block.west());
                    break;
                default: break;
            }
        }
    };
}
;
export function RoutineLogisticsSenderTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            const frame = analysis.block.above()?.getItemStack(1);
            if (!frame || !realm_property.ExpendEnergy(analysis.block, -20) || routineLogisticsRequest.size < 1)
                return;
            const channel = [...routineLogisticsRequest].filter(info => {
                const split = info[0].split('•');
                return split[0] == analysis.dimension.id && split[1] == frame.typeId;
            });
            const containers = [
                analysis.block.west()?.getComponent('inventory')?.container,
                analysis.block.east()?.getComponent('inventory')?.container,
                analysis.block.north()?.getComponent('inventory')?.container,
                analysis.block.south()?.getComponent('inventory')?.container,
            ];
            const judge = new Map(channel.map(info => [info[0].split('•')[2], info[1]]));
            containers.forEach(container => {
                if (!container)
                    return;
                for (let index = 0; index < container.size; index++) {
                    const item = container.getItem(index);
                    if (!item)
                        continue;
                    const result = judge.get(item.typeId);
                    if (!result)
                        continue;
                    const block = analysis.dimension.getBlock(result);
                    if (!block)
                        continue;
                    const inventory = block.getComponent('inventory')?.container;
                    if (!inventory)
                        continue;
                    inventory.addItem(item);
                    container.setItem(index);
                    return;
                }
            });
            routineLogisticsRequest = new Map([...routineLogisticsRequest].filter(info => {
                const split = info[0].split('•');
                return split[0] != analysis.dimension.id || split[1] != frame.typeId;
            }));
        }
    };
}
;
export function SurpassLogisticsSenderTrigger() {
    return {
        onTick(source) {
            const analysis = TickComponentTrigger(source);
            const frame = analysis.block.above()?.getItemStack(1);
            if (!frame || !realm_property.ExpendEnergy(analysis.block, -30) || surpassDimensionRequest.size < 1)
                return;
            const channel = [...surpassDimensionRequest].filter(info => info[0].split('•')[0] == frame.typeId);
            const containers = [
                analysis.block.west()?.getComponent('inventory')?.container,
                analysis.block.east()?.getComponent('inventory')?.container,
                analysis.block.north()?.getComponent('inventory')?.container,
                analysis.block.south()?.getComponent('inventory')?.container,
            ];
            const judge = new Map(channel.map(info => [info[0].split('•')[1], info[1]]));
            containers.forEach(container => {
                if (!container)
                    return;
                for (let index = 0; index < container.size; index++) {
                    const item = container.getItem(index);
                    if (!item)
                        continue;
                    const result = judge.get(item.typeId);
                    if (!result)
                        continue;
                    const block = result[0].getBlock(result[1]);
                    if (!block)
                        continue;
                    const inventory = block.getComponent('inventory')?.container;
                    if (!inventory)
                        continue;
                    inventory.addItem(item);
                    container.setItem(index);
                    return;
                }
            });
            surpassDimensionRequest = new Map([...surpassDimensionRequest].filter(info => info[0].split('•')[0] != frame.typeId));
        }
    };
}
;
